package com.efuture.chaptersix

/* @Description:Kotlin语言泛型扩展函数
 * @Auther: zhaoshanshan
 * @Date: 2022/03/11/5:03 下午
 */
//Strnig类型输出长度
fun <T> T.showStringContentLength() = if(this is String) "你输入的字符串长度是:${this.length}" else "你输入的内容不是字符串"

//显示调用时间
fun<T> T.showCallTime() = println("调用时间为:${System.currentTimeMillis()},调用内容为:$this")

//显示调用者类型
fun<INPUTTYPE> INPUTTYPE.callType()= println(
    when(this){
        is String->"String类型"
        is Int->"Int类型"
        is Boolean->"Boolean类型"
        is Char->"Char类型"
        is Float->"Float类型"
        is Double->"is Double类型"
        is Long ->"is Long类型"
        is Unit->"Unit 类型"
        else->"未知类型"
    }
)
fun main() {

    //调用字符串长度输出函数
    println("123".showStringContentLength())
    println(123.showStringContentLength())
    println(true.showStringContentLength())
    println(234.5.showStringContentLength())

    //显示调用时间输出
    123.showCallTime()
    true.showCallTime()
    123.4.showCallTime()

    //显示调用者类型
    123.callType();
    123.4.callType()
    true.callType()
    "123".callType()
    'C'.showStringContentLength().callType()

}